<?php
namespace Home\Model;
use Think\Model;
class ProductModel extends Model {
	
	public function Product_list($pageNo,$pageSize,$where)
	{    
		
		 $product=M('product');
		 $count['count']=$product->count();
		 $count['countpage']=ceil($count['count']/$pageSize);
		 
		 if($pageNo>=$count['countpage']){
			$pageNo=$count['countpage'];
		 }
		 if($pageNo<=0){
		 	$pageNo=1;
		 }
		 
		 
		 $product_list=$product->where($where)->limit(($pageNo-1)*$pageSize,$pageSize)->select();
		 
		 $count['pageSize']=$pageSize;
		 $count['pageNo']=$pageNo;
		 $count['num']=$count['countpage']-4;
		
		 $result['product_list']=$product_list;
		 $result['count']=$count;
		 $result['data']=$data;
		 return $result;
		 
	}
	
	public function searchList($sku='',$default_styles='',$independent_product='',$brand,$logo='',$product_material='',$product_type='',$weight_before='',$weight_after='',$cost_price_before='',$cost_price_after='',$ali_lt_start='',$ali_lt_end='',$ali_gt_start='',$ali_gt_end='',$aliexpress_start='',$aliexpress_end='',$ioffer_start='',$ioffer_end='',$custom_one='',$custom_two='',$custom_three='',$custom_four='',$supplier='',$buyer='',$starttime='',$endtime='',$pageNo=1,$pageSize=10){
		
		$where='1=1';
		$where.=" and status = 1";
		
		//模糊查询sku
	    if(!empty($sku))
		{
			$where.=' and sku like "%'.$sku.'%"';
			//$data['sku']=$sku;
		}
		//查询默认款式产品
		if(!empty($default_styles))
		{
			$where.=' and default_styles = '.$default_styles.'';
		}
		
		//查询所有自主产品
		if(!empty($independent_product))
		{
			$where.=' and independent_product = '.$independent_product.'';
		}
		
		
		//查询所有自主产品
		if(!empty($brand))
		{
			$where.=' and brand = "'.$brand.'"';
		}
		
		
		//查询产品是否有logo
		if(!empty($logo))
		{
			$where.=' and logo = '.$logo.'';
		}
		
		//根据产品材质查询
		if(!empty($product_material))
		{
			$where.=' and product_material = "'.$product_material.'"';
		}
		//根据产品类型查询
		if(!empty($product_type))
		{
			$where.=' and product_type = "'.$product_type.'"';
		}
		
		//根据创建时间查询 
		 if(!empty($weight_before))
		{
			$where.=" and weight >= ".$weight_before."";
		}
		if(!empty($weight_after))
		{
			$where.=" and weight <= ".$weight_after."";
		}
		
		//根据成本价查询 
	 	if(!empty($cost_price_before))
		{
			$where.=" and cost_price >= ".$cost_price_before."";
		}
		if(!empty($cost_price_after))
		{
			$where.=" and cost_price <= ".$cost_price_after."";
		}
		
		//根据小于50件时阿里指导价查询 
	 	if(!empty($ali_lt_start))
		{
			$where.=" and ali_lt >= ".$ali_lt_start."";
		}
		if(!empty($ali_lt_end))
		{
			$where.=" and ali_lt <= ".$ali_lt_end."";
		}
		
		//根据大于50件时阿里指导价查询 
	 	if(!empty($ali_gt_start))
		{
			$where.=" and ali_gt >= ".$ali_gt_start."";
		}
		if(!empty($ali_gt_end))
		{
			$where.=" and ali_gt <= ".$ali_gt_end."";
		}
		
		//根据速卖通指导价查询 
	 	if(!empty($aliexpress_start))
		{
			$where.=" and aliexpress >= ".$aliexpress_start."";
		}
		if(!empty($aliexpress_end))
		{
			$where.=" and aliexpress <= ".$aliexpress_end."";
		}
		
		
		//根据IOFFER指导价查询 
	 	if(!empty($ioffer_start))
		{
			$where.=" and ioffer >= ".$ioffer_start."";
		}
		if(!empty($ioffer_end))
		{
			$where.=" and ioffer <= ".$ioffer_end."";
		}
		
		//根据自定义管理1查询
		if(!empty($custom_one))
		{
			$where.=' and custom_one = "'.$custom_one.'"';
		}
		
		//根据自定义管理2查询
		if(!empty($custom_two))
		{
			$where.=' and custom_two = "'.$custom_two.'"';
		}
		
		//根据自定义管理3查询
		if(!empty($custom_three))
		{
			$where.=' and custom_three = "'.$custom_three.'"';
		}
		
		
		//根据自定义管理4查询
		if(!empty($custom_four))
		{
			$where.=' and custom_four = "'.$custom_four.'"';
		}
		
		//根据供应商查询
		if(!empty($supplier))
		{
			$where.=' and supplier = "'.$supplier.'"';
		}
		//根据采购员查询
		if(!empty($buyer))
		{
			$where.=' and buyer = "'.$buyer.'"';
		}
		
		//根据创建时间查询
		 if(!empty($starttime))
		{	$starttime .= " 00:00:00";
			$where.=" and addtime >= '".$starttime."'";
		}
		if(!empty($endtime))
		{
			$endtime .= " 59:59:59";
			$where.=" and addtime <= '".$endtime."'";
		}
		
		$product=M('product');
		
		$count['count']=$product->where($where)->count();
		$count['countpage']=ceil($count['count']/$pageSize);
		if($pageNo>=$count['countpage']){
			$pageNo=$count['countpage'];
		}
		if($pageNo<=0){
			$pageNo=1;
		}
		
		if(empty($pageNo) && empty($pageSize))
		{
			$product_list=$product->where($where)->order("addtime desc")->select();
		}
		else
		{
			$product_list=$product->where($where)->order("addtime desc")->limit(($pageNo-1)*$pageSize,$pageSize)->select();
		} 
		$count['pageSize']=$pageSize;
		$count['pageNo']=$pageNo;
		$count['num']=$count['countpage']-4;
		
		$result['product_list']=$product_list;
		$result['count']=$count;
		$result['data']=$data;
		return $result;
	}
	
	
	
	public function searchListAll($sku='',$default_styles='',$independent_product='',$brand,$logo='',$product_material='',$product_type='',$weight_before='',$weight_after='',$cost_price_before='',$cost_price_after='',$ali_lt_start='',$ali_lt_end='',$ali_gt_start='',$ali_gt_end='',$aliexpress_start='',$aliexpress_end='',$ioffer_start='',$ioffer_end='',$custom_one='',$custom_two='',$custom_three='',$custom_four='',$supplier='',$buyer='',$starttime='',$endtime='',$pageNo=1,$pageSize=10){
		
		$where='1=1';
		$where.=" and status = 1";
		
		//模糊查询sku
	    if(!empty($sku))
		{
			$where.=' and sku like "%'.$sku.'%"';
			//$data['sku']=$sku;
		}
		//查询默认款式产品
		if(!empty($default_styles))
		{
			$where.=' and default_styles = '.$default_styles.'';
		}
		
		//查询所有自主产品
		if(!empty($independent_product))
		{
			$where.=' and independent_product = '.$independent_product.'';
		}
		
		
		//查询所有自主产品
		if(!empty($brand))
		{
			$where.=' and brand = "'.$brand.'"';
		}
		
		
		//查询产品是否有logo
		if(!empty($logo))
		{
			$where.=' and logo = '.$logo.'';
		}
		
		//根据产品材质查询
		if(!empty($product_material))
		{
			$where.=' and product_material = "'.$product_material.'"';
		}
		
		//根据产品类型查询
		if(!empty($product_type))
		{
			$where.=' and product_type = "'.$product_type.'"';
		}
		
		//根据创建时间查询 
		 if(!empty($weight_before))
		{
			$where.=" and weight >= ".$weight_before."";
		}
		if(!empty($weight_after))
		{
			$where.=" and weight <= ".$weight_after."";
		}
		
		//根据成本价查询 
	 	if(!empty($cost_price_before))
		{
			$where.=" and cost_price >= ".$cost_price_before."";
		}
		if(!empty($cost_price_after))
		{
			$where.=" and cost_price <= ".$cost_price_after."";
		}
		
		//根据小于50件时阿里指导价查询 
	 	if(!empty($ali_lt_start))
		{
			$where.=" and ali_lt >= ".$ali_lt_start."";
		}
		if(!empty($ali_lt_end))
		{
			$where.=" and ali_lt <= ".$ali_lt_end."";
		}
		
		//根据大于50件时阿里指导价查询 
	 	if(!empty($ali_gt_start))
		{
			$where.=" and ali_gt >= ".$ali_gt_start."";
		}
		if(!empty($ali_gt_end))
		{
			$where.=" and ali_gt <= ".$ali_gt_end."";
		}
		
		//根据速卖通指导价查询 
	 	if(!empty($aliexpress_start))
		{
			$where.=" and aliexpress >= ".$aliexpress_start."";
		}
		if(!empty($aliexpress_end))
		{
			$where.=" and aliexpress <= ".$aliexpress_end."";
		}
		
		
		//根据IOFFER指导价查询 
	 	if(!empty($ioffer_start))
		{
			$where.=" and ioffer >= ".$ioffer_start."";
		}
		if(!empty($ioffer_end))
		{
			$where.=" and ioffer <= ".$ioffer_end."";
		}
		
		//根据自定义管理1查询
		if(!empty($custom_one))
		{
			$where.=' and custom_one = "'.$custom_one.'"';
		}
		
		//根据自定义管理2查询
		if(!empty($custom_two))
		{
			$where.=' and custom_two = "'.$custom_two.'"';
		}
		
		//根据自定义管理3查询
		if(!empty($custom_three))
		{
			$where.=' and custom_three = "'.$custom_three.'"';
		}
		
		
		//根据自定义管理4查询
		if(!empty($custom_four))
		{
			$where.=' and custom_four = "'.$custom_four.'"';
		}
		
		//根据供应商查询
		if(!empty($supplier))
		{
			$where.=' and supplier = "'.$supplier.'"';
		}
		//根据采购员查询
		if(!empty($buyer))
		{
			$where.=' and buyer = "'.$buyer.'"';
		}
		
		//根据创建时间查询
		 if(!empty($starttime))
		{	$starttime .= " 00:00:00";
			$where.=" and addtime >= '".$starttime."'";
		}
		if(!empty($endtime))
		{
			$endtime .= " 59:59:59";
			$where.=" and addtime <= '".$endtime."'";
		}
		
		$product=M('product');
		
		$count['count']=$product->where($where)->count();
		$count['countpage']=ceil($count['count']/$pageSize);
		if($pageNo>=$count['countpage']){
			$pageNo=$count['countpage'];
		}
		if($pageNo<=0){
			$pageNo=1;
		}
		if(empty($pageNo) && empty($pageSize))
		{
			$product_list=$product->where($where)->order("addtime desc")->select();
		}
		else
		{
			$product_list=$product->where($where)->order("addtime desc")->select();
		} 
		
		$count['pageSize']=$pageSize;
		$count['pageNo']=$pageNo;
		$count['num']=$count['countpage']-4;
		
		$result['product_list']=$product_list;
		$result['count']=$count;
		$result['data']=$data;
		return $result;
	}
	
	
	public function recycleList($sku='',$default_styles='',$independent_product='',$brand,$logo='',$product_material='',$product_type='',$weight_before='',$weight_after='',$cost_price_before='',$cost_price_after='',$ali_lt_start='',$ali_lt_end='',$ali_gt_start='',$ali_gt_end='',$aliexpress_start='',$aliexpress_end='',$ioffer_start='',$ioffer_end='',$custom_one='',$custom_two='',$custom_three='',$custom_four='',$supplier='',$buyer='',$starttime='',$endtime='',$pageNo=1,$pageSize=10){
		
		$where='1=1';
		$where.=" and status = 2";
		
		//模糊查询sku
	    if(!empty($sku))
		{
			$where.=' and sku like "%'.$sku.'%"';
			//$data['sku']=$sku;
		}
		//查询默认款式产品
		if(!empty($default_styles))
		{
			$where.=' and default_styles = '.$default_styles.'';
		}
		
		//查询所有自主产品
		if(!empty($independent_product))
		{
			$where.=' and independent_product = '.$independent_product.'';
		}
		
		
		//查询所有自主产品
		if(!empty($brand))
		{
			$where.=' and brand = "'.$brand.'"';
		}
		
		
		//查询产品是否有logo
		if(!empty($logo))
		{
			$where.=' and logo = '.$logo.'';
		}
		
		//根据产品材质查询
		if(!empty($product_material))
		{
			$where.=' and product_material = "'.$product_material.'"';
		}
		
		//根据产品类型查询
		if(!empty($product_type))
		{
			$where.=' and product_type = "'.$product_type.'"';
		}
		
		//根据创建时间查询 
		 if(!empty($weight_before))
		{
			$where.=" and weight >= ".$weight_before."";
		}
		if(!empty($weight_after))
		{
			$where.=" and weight <= ".$weight_after."";
		}
		
		//根据成本价查询 
	 	if(!empty($cost_price_before))
		{
			$where.=" and cost_price >= ".$cost_price_before."";
		}
		if(!empty($cost_price_after))
		{
			$where.=" and cost_price <= ".$cost_price_after."";
		}
		
		//根据小于50件时阿里指导价查询 
	 	if(!empty($ali_lt_start))
		{
			$where.=" and ali_lt >= ".$ali_lt_start."";
		}
		if(!empty($ali_lt_end))
		{
			$where.=" and ali_lt <= ".$ali_lt_end."";
		}
		
		//根据大于50件时阿里指导价查询 
	 	if(!empty($ali_gt_start))
		{
			$where.=" and ali_gt >= ".$ali_gt_start."";
		}
		if(!empty($ali_gt_end))
		{
			$where.=" and ali_gt <= ".$ali_gt_end."";
		}
		
		//根据速卖通指导价查询 
	 	if(!empty($aliexpress_start))
		{
			$where.=" and aliexpress >= ".$aliexpress_start."";
		}
		if(!empty($aliexpress_end))
		{
			$where.=" and aliexpress <= ".$aliexpress_end."";
		}
		
		
		//根据IOFFER指导价查询 
	 	if(!empty($ioffer_start))
		{
			$where.=" and ioffer >= ".$ioffer_start."";
		}
		if(!empty($ioffer_end))
		{
			$where.=" and ioffer <= ".$ioffer_end."";
		}
		
		//根据自定义管理1查询
		if(!empty($custom_one))
		{
			$where.=' and custom_one = "'.$custom_one.'"';
		}
		
		//根据自定义管理2查询
		if(!empty($custom_two))
		{
			$where.=' and custom_two = "'.$custom_two.'"';
		}
		
		//根据自定义管理3查询
		if(!empty($custom_three))
		{
			$where.=' and custom_three = "'.$custom_three.'"';
		}
		
		
		//根据自定义管理4查询
		if(!empty($custom_four))
		{
			$where.=' and custom_four = "'.$custom_four.'"';
		}
		
		//根据供应商查询
		if(!empty($supplier))
		{
			$where.=' and supplier = "'.$supplier.'"';
		}
		//根据采购员查询
		if(!empty($buyer))
		{
			$where.=' and buyer = "'.$buyer.'"';
		}
		//根据创建时间查询
		 if(!empty($starttime) && $starttime !=' ')
		{	$starttime .= " 00:00:00";
			$where.=" and addtime >= '".$starttime."'";
		}
		if(!empty($endtime) )
		{
			$endtime .= " 00:00:00";
			$where.=" and addtime <= '".$endtime."'";
		}
		
		$product=M('product');
		
		$count['count']=$product->where($where)->count();
		$count['countpage']=ceil($count['count']/$pageSize);
		if($pageNo>=$count['countpage']){
			$pageNo=$count['countpage'];
		}
		if($pageNo<=0){
			$pageNo=1;
		}
		if(empty($pageNo) && empty($pageSize))
		{
			$recycle_list=$product->where($where)->order("addtime desc")->select();
		}
		else
		{
			$recycle_list=$product->where($where)->order("addtime desc")->limit(($pageNo-1)*$pageSize,$pageSize)->select();
		} 
		
		$count['pageSize']=$pageSize;
		$count['pageNo']=$pageNo;
		$count['num']=$count['countpage']-4;
		
		$result['recycle_list']=$recycle_list;
		$result['count']=$count;
		$result['data']=$data;
		return $result;
	}
	
	
    public function brand_info($brands)
	{
		 $brand=M('brand');
		 $where['brand'] = $brands;
		 $brandinfo=$brand->field("brand")->where($where)->find();
	
		 return $brandinfo;
	}
	
	
	
}
?>